cmake_minimum_required(VERSION 3.5)

if (UNIX AND NOT APPLE)
	set(LINUX TRUE)
endif()

project(SampleOmni VERSION 2020.4 LANGUAGES CXX)

INCLUDE_DIRECTORIES(../../Include/BearLibTerminal)

set(CMAKE_SKIP_RPATH TRUE)

# Detect system bitness
math(EXPR BITNESS "8*${CMAKE_SIZEOF_VOID_P}")

# Release flags
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g0")
if(NOT APPLE)
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s")
endif()

# Debug flags
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")

# Common flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
if(WIN32)
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -mwindows")
elseif(LINUX)
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()

set(SOURCE_FILES ./Source/Main.cpp
                 ./Source/Common.cpp
                 ./Source/WindowsGlyphList4.cpp
                 ./Source/BasicOutput.cpp
                 ./Source/DefaultFont.cpp
                 ./Source/Tilesets.cpp
                 ./Source/Sprites.cpp
                 ./Source/ManualCellsize.cpp
                 ./Source/AutoGenerated.cpp
                 ./Source/MultipleFonts.cpp
                 ./Source/TextAlignment.cpp
                 ./Source/FormattedLog.cpp
                 ./Source/Layers.cpp
                 ./Source/ExtendedBasics.cpp
                 ./Source/ExtendedInterlayer.cpp
                 ./Source/ExtendedSmoothScroll.cpp
                 ./Source/DynamicSprites.cpp
                 ./Source/Speed.cpp
                 ./Source/Keyboard.cpp
                 ./Source/Mouse.cpp
                 ./Source/TextInput.cpp
                 ./Source/InputFiltering.cpp
                 ./Source/WindowResize.cpp
                 ./Source/Pick.cpp)

set(HEADER_FILES ./Source/Common.hpp)

include_directories(${CMAKE_SOURCE_DIR}/Terminal/Include/C)
add_executable(SampleOmni ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(SampleOmni BearLibTerminal)
if (LINUX)
    target_link_libraries(SampleOmni -Wl,-R.)
endif()
if(WIN32)
	target_link_libraries(SampleOmni winmm.lib)
endif()

set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/Output/${CMAKE_SYSTEM_NAME}${BITNESS})
set_target_properties(SampleOmni PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
